class GameOverRankItem extends egret.DisplayObjectContainer {
	private headIcon: egret.Bitmap;
	private headMask: egret.Shape;

	private rankTxt: egret.TextField;
	private nameTxt: egret.TextField;

	private scoreContainer: egret.DisplayObjectContainer;
	public constructor(index: number, data: any,width:number=213,height:number=268,bgColor:number=0x000000) {
		super();
		let color = data.isMine ? 0x0cb30c: 0x231f20;
		let alpha = data.isMine ? 0.04 : 0.7;
		alpha = 1;
		//背景
		// let bg = new egret.Shape();
		// bg.graphics.beginFill(bgColor, alpha);
		// bg.graphics.drawRect(0, 0, width, height);
		// bg.graphics.endFill();
		// this.addChild(bg);
		//排名
		let rank = this.rankTxt = new egret.TextField();
		rank.y = 22;
		rank.text = data.rank;
		rank.width = width;
		rank.textAlign = egret.HorizontalAlign.CENTER;
		rank.size = 30;
		rank.textColor = color;

		//rank.italic = true;

		let rankNum = data.rank;
		// if (rankNum == 1) {
		// 	rank.textColor = 0xfa7e00;
		// } else if (rankNum == 2) {
		// 	rank.textColor = 0xfdbf1e;
		// } else if (rankNum == 3) {
		// 	rank.textColor = 0xfad313;
		// }

		this.addChild(rank);
		let headWH = 78;
		//头像
		let imask = this.headMask = new egret.Shape();
		imask.graphics.beginFill(0xffffff);
		imask.graphics.drawRoundRect((width-headWH)/2, rank.y + rank.height + 16, headWH, headWH, 15, 15);
		imask.graphics.endFill();
		this.addChild(imask);

		var head = this.headIcon = new egret.Bitmap();
		head.width = head.height = headWH;
		
		 head.mask = this.headMask;

		let imageLoader = new egret.ImageLoader();
		imageLoader.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
			let imageLoader = <egret.ImageLoader>event.currentTarget;
			var bgtexture = new egret.Texture();
			bgtexture._setBitmapData(imageLoader.data);
			this.headIcon.texture = bgtexture;
		}, this);
		imageLoader.load(data.avatarUrl);
		this.addChild(head);

		head.x = (width-headWH)/2;
		head.width = headWH;
		head.height = headWH;
		head.y = rank.y + rank.height + 16;

		//名字
		let nicktxt = this.nameTxt = new egret.TextField();
		nicktxt.y = head.y + head.height + 24;
		nicktxt.text = ParseUtils.getInstance().parseName(data.nickname);
		nicktxt.width = width;
		nicktxt.textAlign = "center";
		nicktxt.textColor = color;
		nicktxt.size = 26;
		this.addChild(nicktxt);
		//分数
		//let score = ""+data.weekScore;
		let score = data.highestScore
		if (GlobalData.textureArr && GlobalData.textureArr.length == 10) {
			
			// let scoreItemWidth = 20;
			// let scoreItemHeight = 25;
			
			// let fromX:number =  (width - scoreItemWidth*score.length)/2;
			// let fromY = nicktxt.y + nicktxt.height + 16;
			// for (let i = 0; i < score.length; i++) {
			// 	let sn = parseInt(score[i]);
			// 	let texture = GlobalData.textureArr[sn];
			// 	let bitmap = new egret.Bitmap(texture);
			// 	bitmap.x = fromX+scoreItemWidth*i;
			// 	bitmap.y = fromY;
			// 	bitmap.height = scoreItemHeight;
			// 	bitmap.width = scoreItemWidth;
			// 	this.addChild(bitmap);
				
			// }
			let numtxt = new egret.TextField();
			numtxt.width = width;
			numtxt.textAlign = egret.HorizontalAlign.CENTER;
			numtxt.y = nicktxt.y + nicktxt.height+16;
			numtxt.size = 30;
			//numtxt.bold = true;
			//numtxt.text = data.weekScore;
			numtxt.text = data.highestScore;
			numtxt.textColor = color;
			this.addChild(numtxt);
			
		} else {
			let numtxt = new egret.TextField();
			numtxt.width = width;
			numtxt.textAlign = egret.HorizontalAlign.CENTER;
			numtxt.y = nicktxt.y + nicktxt.height+16;
			numtxt.size = 30;
			//numtxt.bold = true;
			//numtxt.text = data.weekScore;
			numtxt.text = data.highestScore;
			numtxt.textColor = color;
			this.addChild(numtxt);
		}
	}
}